/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.bme.j2ee.v37zen.beans;

import hu.bme.j2ee.v37zen.entities.User;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Kiss Dániel
 */
@Stateless
@LocalBean
public class LoginBean {

    @PersistenceContext
    EntityManager em;
    
    public User loginUser(User user){
        if(user == null){
            return null;
        }
        user = em.merge(user);
        user.setLogedIn(true);
        em.flush();
        return user;
    }
    
    public User loginOut(User user){
        if(user == null){
            return null;
        }
        user = em.merge(user);
        user.setLogedIn(false);
        em.flush();
        return user;
    }

}
